<template>
  <basic-container>
    <avue-crud
      :data="data"
      :option="option"
      :page.sync="page"
      @on-load="rowLoad"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @row-save="rowSave"
      @size-change="sizeChange"
      @current-change="currentChange">
    </avue-crud>
  </basic-container>
</template>

<script>
import avue from '@/mixins/avue.js'
import {
  template_page,
  template_edit,
  template_delete,
  template_add
} from '@/api/core/system'

export default {
  mixins: [avue],
  data () {
    return {
      data: [],
      option: {
        dialogWidth: '30%',
        span: 24,
        column: [
          {
            label: '消息类型',
            prop: 'type',
            dicData: [],
            props: {
              label: 'name',
              value: 'id'
            }
          },
          {
            label: '模板标题',
            prop: 'title'
          },
          {
            label: '模板标识',
            prop: 'code'
          },
          {
            label: '模板内容',
            prop: 'content',
            type: 'textarea'
          },
          {
            label: '状态',
            prop: 'status',
            type: 'radio',
            value: '1',
            dicData: [
              {
                label: '启用',
                value: '1'
              },
              {
                label: '停用',
                value: '0'
              }

            ]
          }
        ]
      }
    }
  },
  created () {
    role_tree().then(res => {
      this.findObject(this.option.column, 'roleIds').dicData = res.result
    })
  },
  methods: {
    rowLoad () {
      template_page(this.params).then((res) => {
        this.data = this.$s.res(res).records
      })
    },
    rowSave (row, loading, done) {
      template_add(row)
        .then((res) => {
          this.$s.suc(res)
        })
        .then(() => {
          this.rowLoad()
          done()
          loading()
        })
    },
    rowUpdate (row, loading, done) {
      template_edit(row)
        .then((res) => {
          this.$s.suc(res)
        })
        .then(() => {
          this.rowLoad()
          done()
          loading()
        })
    },
    rowDel (row, loading, done) {
      this.$confirm('确定数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          template_delete({ ids: row.id }).then((res) => {
            this.$s.suc(res)
          }).then(() => {
            this.rowLoad()
            done()
            loading()
          })
        })
    }
  },
  mounted () { }
}
</script>

<style lang="scss" scoped>

</style>
